package day02.test;

public class testSort {
public static void main(String[] args) {
	int b[]= {1,2,3,4,5,6,7};
	//bubbleSort(b);
//	selectionSort(b);
System.out.println(quickSort(b,3));
}
//冒泡排序
 public static void bubbleSort(int []a) {
	 for(int i=0;i<a.length-1;i++) {
		 
		 for(int j=0;j<a.length-1-i;j++) {
			 if(a[j]<a[j+1]) {
				 int temp;
				 temp=a[j];
				 a[j]=a[j+1];
				 a[j+1]=temp;
				 
			 }
			 
			 
		 }
	 }
	 
	 for(int d:a) {
		 System.out.println("一维数组增强:for:"+d);
	 }
 }
//选择排序
 public static void selectionSort(int []a) {
	 for(int d:a) {
		 System.out.println("一维数组增强:for:"+d);
	 }
	 int point ;
	 int temp;
 for(int i=0;i<a.length-1;i++) {
		point=i;
		 for(int j=i+1;j<a.length;j++) {
	      if(a[j]<a[point]) {
	    	  point=j;
	    	  
	      }
		 }
    temp=a[i];
    a[i]=a[point];
    a[point]=temp;
 }
 System.out.println("****");
 for(int d:a) {
	 System.out.println("一维数组增强:for:"+d);
 }
 }
 //二分查找
 public static int quickSort(int a[],int num) {
	 int high= a.length-1;
	 int low=0;
	 
	 while(low<=high) {
		 int mid=(high+low)/2;
		if(a[mid]==num) {
			
			return mid+1;
		}else if(num<a[mid]){
			high=mid-1;
			
		}else {
			
			low=mid+1;
		}
	 }
	return -1;
 }
}
